<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script type="text/javascript">
            function fun(id){
                let node=document.createElement("img");
                node.setAttribute("src", "js/img/ok.png");
                node.style.width = "15px"; //设置图片大小
                node.style.height = "15px";
                let span = document.getElementById(id);
                span.innerHTML = "";
                span.appendChild(node);
            }
            function check(){
                let isValid = true; // 初始化一个标志变量,控制表单是否提交
                let d1 = document.getElementById("d1").value;
                let d2 = document.getElementById("d2").value;
                let d3 = document.getElementById("d3").value;
                let d4 = document.getElementById("d4").value;
                let d5 = document.getElementById("d5").value;
                if(d1.length>10){
                    document.getElementById("r1").innerHTML = "姓名不能超过10位！";
                    isValid = false;
                }else{
                    fun("r1")
                }
				
                if(d1.length==""){
                    document.getElementById("r1").innerHTML = "姓名不能为空！";
                    isValid = false;
                }else{
                    fun("r1")
                }
				
                if(isNaN(d2) || d2 < 0 || d2 > 150||d2==""){
                    document.getElementById("r2").innerHTML = "年龄应该是1-150的数字！";
                    isValid = false;
                }else{
                    fun("r2")
                }
				
                if(d3.length<6){
                    document.getElementById("r3").innerHTML = "密码不能少于6位！";
                    isValid = false;
                }else{
                    fun("r3")
                }
                if(d4!=d3||d3==""){
                    document.getElementById("r4").innerHTML = "两次密码不一致";
                    isValid = false;
				}else{
                    fun("r4")
                }

                let reg = /^1\d{10}$/;
                if(!reg.test(d5)){
                    document.getElementById("r5").innerHTML = "手机号码为1开头的11位数字！";
                    isValid = false;
                }else{
                    fun("r5")
                }
				
                if (!isValid) {
                    document.getElementById("d6").innerHTML = "请根据提示修改数据";
                } else {
                    document.getElementById("d6").innerHTML = "注册成功！";
                }
                return isValid; // 根据标志变量决定是否提交表单
            }
        </script>
    </head>
    <body>
        <form onsubmit="check(); return false;">
            输入姓名：<input type="text" id="d1"><span id="r1"></span><br>
            输入年龄：<input type="text" id="d2"><span id="r2"></span><br>
            输入密码：<input type="password" id="d3"><span id="r3"></span><br>
            确认密码：<input type="password" id="d4"><span id="r4"></span><br>
            手机号码：<input type="text" id="d5"><span id="r5"></span><br>
            <input type="submit" value="注册"/>
        </form>
        <p id="d6"></p> 
    </body>
</html>